<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no" />
		<title>首页</title>
		<link rel="stylesheet" type="text/css" href="../css/aui.css" />
		<link rel="stylesheet" type="text/css" href="../css/ffxiang.css" />
		<link rel="stylesheet" type="text/css" href="../css/view.css" />
		<style>
			#fx-header {
				height: 0;
				min-height: 0;
			}
			#video {
				width: 100%;
				height: 12rem;
				background: #000;
			}
		</style>
	</head>
	<body>
		<header class="aui-bar aui-bar-nav fx-view-header" id="fx-header"></header>
		<div id="video"></div>
		<footer class="aui-bar aui-bar-tab fx-view-footer" id="fx-footer">
			<div class="aui-bar-tab-item aui-padded-l-15 aui-padded-r-15" tapmode style="width: auto;">
				<div class="search-input aui-font-size-14" tapmode onclick="pingAdd()">
					请输入评论内容
				</div>
			</div>
			<div class="aui-bar-tab-item" tapmode style="width: 2.2rem;" tapmode  onclick="gundong()">
				<div class="aui-badge" id="pingNum" data-num="0">
					0
				</div>
				<i class="aui-iconfont aui-icon-comment"></i>
			</div>
			<div class="aui-bar-tab-item" id="shoucang" tapmode onclick="shoucang(this)" data-id='1' style="width: 2.2rem;">
				<i class="aui-iconfont aui-icon-star"></i>
			</div>
			<div class="aui-bar-tab-item" tapmode onclick="fenxiang()" style="width: 2.2rem;margin-right: 0.5rem;">
				<i class="aui-iconfont aui-icon-share"></i>
			</div>
		</footer>
	</body>
	<script type="text/javascript" src="../script/zepto.min.js"></script>
	<script type="text/javascript" src="../script/api.js"></script>
	<script type="text/javascript" src="../script/ffxiang.js"></script>
	<script type="text/javascript">
		var id, inputField, uid = 0, fan, moviePlayer, znashiti;
		apiready = function() {
			_heibai(1)
			moviePlayer = api.require('moviePlayer');
			id = api.pageParam['id'];
			fan = api.pageParam['fan'];
			if (!id) {
				_alert("文章不存在或已被删除！", function(ret) {
					_hone();
				})
			}
			// 判断返回键
			api.addEventListener({
				name : 'keyback'
			}, function(ret, err) {
				c()
			});

			api.addEventListener({
				name : 'yejian'
			}, function(ret, err) {
				if (ret) {
					_yejians();
				}
			});
			var header = $api.byId('fx-header');
			$api.fixStatusBar(header);
			var headerh = $api.offset(header).h;
			headerh = headerh + $api.offset($api.dom('#video')).h
			var body_h = api.winHeight;
			$api.fixTabBar($api.byId('fx-footer'))
			var footerh = $api.offset($api.byId('fx-footer')).h;
			api.openFrame({
				name : 'view',
				url : html_win + 'view.html',
				bounces : true,
				reload : true,
				rect : {
					x : 0,
					y : headerh,
					w : 'auto',
					h : body_h - headerh - footerh
				},
				pageParam : api.pageParam,
			})
			video()
			//Window 离开屏幕的事件
			//			api.addEventListener({
			//			    name:'viewdisappear'
			//			}, function(ret, err){
			//				playModule.pause();
			//				// 关闭全屏
			//				api.setFullScreen({
			//				    fullScreen: false
			//				});
			//			});
			// 进入屏幕时间
			api.addEventListener({
				name : 'viewappear'
			}, function(ret, err) {
				_heibai(1)
				//				api.setFullScreen({
				//				    fullScreen: true
				//				});
				//				if(znashiti==1){
				//					playModule.start();
				//				}
				//				znashiti=1
				// 每天阅读次数奖励
				setTimeout(function() {
					_daily({
						name : 'money_news'
					})
				}, _config.yaoqing.money_news_time)
			});
			//			playModule.addEventListener({
			//			    name: 'backBtn'
			//			}, function(ret, err) {
			//				if(ret.status){
			//					_close()
			//				}
			//			});
			// 监听返回键
			//			api.addEventListener({
			//				name : 'keyback'
			//			}, function(ret, err) {
			//				// 判断是否全屏
			//				playModule.isFullScreen(function(ret, err) {
			//					if(ret.status){
			//						playModule.unfull();
			//						return;
			//					}
			//					_close()
			//				});
			//			});
			//应用进入后台事件
			//			api.addEventListener({
			//				name : 'pause'
			//			}, function(ret, err) {
			//				playModule.pause();
			//				// 关闭全屏
			//				api.setFullScreen({
			//				    fullScreen: false
			//				});
			//			});
			//			// 应用从后台回到前台事件
			//			api.addEventListener({
			//				name : 'resume'
			//			}, function(ret, err) {
			//				playModule.start();
			//			});
			moviePlayer.addEventListener(function(ret){
			    if(ret && ret.eventType == 'back'){
			    	c();
			    }
			});
			// 判断返回键
			api.addEventListener({
				name : 'keyback'
			}, function(ret, err) {
				moviePlayer.isFullscreen(function(ret){
					 if(ret.state){
						moviePlayer.onBack();
					 }else{
							c();
					 }
				});
				return;
			});
			//		Window 离开屏幕的事件
								api.addEventListener({
								    name:'viewdisappear'
								}, function(ret, err){
									moviePlayer.pause();
								});

		}
		function video() {
			console.log(api.pageParam['videoUrl'])
			var h = $('#video').height();
			var a = $('#fx-header').height();
			moviePlayer.open({
				rect : {
					x : 0,
					y : a,
					w : api.winWidth,
					h : h
				},
				videoDirection : 'landscape',
				path : api.pageParam['videoUrl'],
				autoPlay : true,
				autorotation:false,
				styles : {
					head : {
						bg : 'rgba(161,161,161,0)',
						height : 44,
						y : 20,
						backSize : 30,
						backImg : _image + 'leftbofang.png',
					},
					foot : {
						bg : 'rgba(0,0,0,0)',
						height : 44,
						palyBtn : {
							size : 15,
							playImg :  _image + 'fx_bofang_s.png',
							pauseImg : _image + 'fx_zanting_s.png',
							marginLeft : 15
						},
						currentTimeLabel : {
							textSize : 14,
							textColor : "#FFF",
							textWidth : 43,
							marginLeft : 15
						},
						seekBar : {

							sliderW : 20,
							sliderH : 20,
							progressColor : '#696969',
							progressSelected : '#D43D3D',
							marginLeft : 15,
							marginRight : 15
						},
						totalTimeLabel : {
							textSize : 14,
							textColor : "#FFF",
							textWidth : 43,
							marginRight : 15
						},
						fullscreenBtn : {
							size : 30,
							verticalImg : _image + '2019/video_quan.png',
							horizontalImg : _image + '2019/video_quan_tui.png',
						}
					}
				},
			}, function(ret, err) {
				//	console.log(JSON.stringify(ret))
			});
			return;
			playModule.play({
				rect : {
					x : 0,
					y : a,
					w : api.winWidth,
					h : h
				},
				url : api.pageParam['videoUrl'],
				defaultBtn : true,
				enableFull : false,
				isBackBtn : true,
				title : api.pageParam['title'],
				isTopView : true,
				isLocalCache : true,
			});
			return;
			//$('#video').html('<video autoplay="autoplay" src="http://v6.365yg.com/video/m/220a3b4d980b3b94f3eb720da75fd7275151148de70000502f3965f4d5/?Expires=1498321249&AWSAccessKeyId=qh0h9TdcEMoS2oPj7aKX&Signature=p3noHP%2FWRrml6l2%2ByExFXeRgHSM%3D"  controls="true" type="video/mp4" webkit-playsinline="true" style="width: 100%;height: 12.5rem;" playsinline="true"></video>');
			//$('#video').html('<video autoplay="autoplay" poster="'+img+'" src="'+url+'"  controls="true" type="video/mp4" webkit-playsinline="true" style="width: 100%;height: 12rem;" playsinline="true" />')
		}

		// 滚动
		function gundong() {
			var gundong = 'gundong();';
			api.execScript({
				frameName : 'view',
				script : gundong
			});
		}

		// 分享
		function fenxiang() {
			var fenxiang = 'fenxiang();';
			api.execScript({
				frameName : 'view',
				script : fenxiang
			});
		}

		// 收藏
		function shoucang(ojb) {
			if (!_user) {
				_login();
				return;
			}
			_loading()
			var type = $(ojb).data('id');
			if (type == 1) {
				_ajax('api/member/favoriteAdd', function(ret, err) {
					_loadingCloes()
					if (ret.ret) {
						$(ojb).data('id', '2')
						$(ojb).css("color", "#FCACAC")
						_msg(ret.ret)
					} else {
						_msg(ret.err)
					}
				}, {
					aid : id
				})
			} else {
				_ajax('api/member/favoriteDel', function(ret, err) {
					_loadingCloes()
					if (ret.ret) {
						$(ojb).data('id', '1')
						$(ojb).css("color", "")
						_msg(ret.ret)
					} else {
						_msg(ret.err)
					}
				}, {
					aid : id
				})
			}
		}

		// 判断是否收藏
		function _views(shoucang, pingNum) {
			if (shoucang) {
				$('#shoucang').data('id', '2')
				$('#shoucang').css("color", "#FCACAC")
			}
			if (pingNum) {
				$('#pingNum').data('num', pingNum)
				$('#pingNum').text(pingNum)
			} else {
				$('#pingNum').hide();
			}
		}

		// 更新评论数量
		function pingNum() {
			var num = $('#pingNum').data('num')
			$('#pingNum').show();
			$('#pingNum').text(num + 1)
			$('#pingNum').data('num', num + 1)
		}

		// 评论
		function pingAdd() {
			var pingAdd = 'pingAdd();';
			api.execScript({
				frameName : 'view',
				script : pingAdd
			});
		}

		// 标题
		function title(text, uids) {
			uid = uids;
			if (uid || text) {
				$('.aui-title').text(text)
			} else {
				$('.aui-title').text('内容详细')
			}
		}

		function userUrl() {
			if (uid) {
				_url({
					id : uid
				}, 'u_win')
			}
		}

		// 获取底部高度
		function dibugaodu() {
			var h = $api.offset($api.byId('fx-footer')).h;
			api.execScript({
				frameName : 'view',
				script : 'dibugaodu(' + h + ');'
			});
		}
		// 重新播放指定播放地址
		function replay(path){
			moviePlayer.replay({
			    path : path
			});
		}
		function c(){
			var a = api.frames();
			for (var i = 0; i < a.length; i++) {
				console.log(a[i].name)
				if(a[i].name == 'jindu'){
					api.execScript({
						 frameName: 'jindu',
						 script: 'quxiao();'
					});
				}else{
					_close();
				}
			}
		}
	</script>
</html>
